package com.xsky.validator
{
	import mx.validators.ValidationResult;
	import mx.validators.Validator;

	public class MobileValidator extends Validator
	{
		private var mobileInValid:String = "手机号码格式错误";
		private var mobileInValidCode:String = '10003';
		protected var mobileReg:RegExp = /^1(3|5)[0-9]{9}$/;
		
		public function MobileValidator()
		{
			super();
		}
		public function get mobileInvalidError():String
		{
			return mobileInValid;
		}
		public function set mobileInvalidError(invalidStr:String):void
		{
			this.mobileInValid = invalidStr;
		}
		public function doMobileValidation(validator:MobileValidator, value:Object, baseField:String):Array
		{
			var rs:Array = [];
			if(!mobileReg.test(String(value)))
			{
				rs.push(new ValidationResult(true, baseField,validator.mobileInValidCode, validator.mobileInValid));
			}
			return rs;
		}
		override protected function doValidation(value:Object):Array
		{
			var rs:Array = super.doValidation(value);
			var val:String = value?String(value):'';
			if(rs.length>0||(val.length==0)&&!required)
			{
				return rs;
			}
			return doMobileValidation(this,value,null);
		}
	}
}